clc;
clear;
disp('---------------下面为绘图做准备---------------------------')
x=[0:0.01:2,2+eps:0.01:4,4]; 
y=exp(x.^2).*(x<=2)+...
  80./(4-sin(16*pi*x)).*(x>2); 
y(end)=0; %???????????????????

x=[eps,x]; 
y=[0,y]; 

fill(x,y,'g') % 绘制积分区域的填充图形
disp('---------------下面是匿名函数方式---------------------------')

f=@(x)...
    exp(x.^2).*(x<=2)+...
    80./(4-sin(16*pi*x)).*(x>2); 
I=integral(f,0,4)
disp('---------------数值积分---------------------------')
syms x; 
I0=vpa(int(exp(x^2),0,2)+ ...
    int(80/(4-sin(16*pi*x)),2,4))
I2=integral(f,0,4,'RelTol',1e-20) % 数值积分的双精度计算
disp('-----------------下面是分段式函数piecewise-----------------------')
syms x;
f = piecewise(x <= 2, exp(x^2), x > 2, 80/(4 - sin(16*pi*x)));
I = vpa(int(f, x, 0, 4)); % 定积分的解析高精度计算




